package com.cade.agriculturemall.view.login;

import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.LogInCallback;
import com.avos.avoscloud.SaveCallback;
import com.cade.agriculturemall.base.BasePresenter;
import com.cade.agriculturemall.base.IBaseView;

/**
 * Created by Lobby on 2017/11/15.
 */

public class LoginPresenter extends BasePresenter<LoginContract.IView> implements LoginContract.IPresenter {


    public LoginPresenter(LoginContract.IView view) {
        super(view);
    }

    @Override
    public void onResume() {
    }

    @Override
    public void onCreate() {

    }

    @Override
    public void onDestroy() {

    }


    @Override
    public void login(String phone, String psw) {
        mView.showProgress();
//        mView.redirection();
//        AVUser.loginByMobilePhoneNumberInBackground(phone, psw, new LogInCallback<AVUser>() {
//            @Override
//            public void done(AVUser avUser, AVException e) {
//                mView.redirection();
//            }
//        });
        AVUser.logInInBackground(phone, psw, new LogInCallback<AVUser>() {
            @Override
            public void done(AVUser avUser, AVException e) {
                if (e == null) {
                    mView.redirection();

                } else {
                    mView.showError(e.getMessage());
                }
                mView.dismissProgress();
            }
        });

    }
}
